package io.renren.modules.member.service.impl;

import io.renren.modules.member.enums.SportEnums;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.List;

@Component
@ConfigurationProperties(prefix = "standard")
@Data
public class StandardRegionAge implements Serializable {

    private List<RegionAge> regionage1;
    private List<RegionAge> regionage2;
    private List<RegionAge> regionage3;

    public String getGAchv(Integer age, String type) {
        List<RegionAge> targetRegion = null;
        if (StringUtils.equals(type, SportEnums.LEAD_UP.getCode())
            || StringUtils.equals(type, SportEnums.CRANK_ARM.getCode())) {
            targetRegion = regionage1;
        } else if (StringUtils.equals(type, SportEnums.PUSH_UP.getCode())) {
            targetRegion = regionage2;
        } else if (StringUtils.equals(type, SportEnums.SIT_UP.getCode())
                || StringUtils.equals(type, SportEnums.SNAKE_RUN.getCode())
                || StringUtils.equals(type, SportEnums.MIDDLE_RUN.getCode())) {
            targetRegion = regionage3;
        }
        if (CollectionUtils.isEmpty(targetRegion)) {
            return null;
        }
        RegionAge region = targetRegion.stream().filter(e -> e.select(age)).findFirst().orElse(new RegionAge());
        return region.getG();
    }
}

@Data
class RegionAge {
    private Integer min;
    private Integer max;
    private String g;

    public boolean select(Integer age) {
        if (min <= age && max >= age) {
            return true;
        } else {
            return false;
        }
    }
}